package net.ncraft.mc.easyframework.easygame.gamekits.inventorygui;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import javax.swing.*;
import java.util.Arrays;

@Data
@Accessors(chain = true)
public class ItemElement {

    @Setter
    @Getter
    private ItemStack item;
    @Setter
    @Getter
    private int slot;
    @Setter
    @Getter
    private int priority = 0;
    @Getter
    @Setter
    private ElementAction onClick;

    public ItemElement(ItemStack item, int slot, ElementAction onClick) {
        this.item = item;
        this.slot = slot;
        this.onClick = onClick;
    }

    //设置附魔
    public void setEnchantment(Enchantment enchantment, int level) {
        item.addUnsafeEnchantment(enchantment, level);
    }

    public void setAmount(int amount) {
        item.setAmount(amount);
    }

    public void setDisplayName(String name) {
        ItemMeta itemMeta = item.getItemMeta();
        itemMeta.setDisplayName(name);
        item.setItemMeta(itemMeta);
    }

    public void setLore(String... lores) {
        ItemMeta itemMeta = item.getItemMeta();
        itemMeta.setLore(Arrays.stream(lores).toList());
        item.setItemMeta(itemMeta);
    }

}
